package com.example.zhanghehe.myapplication.lessonone

import android.app.ActivityManager
import android.content.Context
import android.opengl.GLSurfaceView
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.Window

class LessonOneActivity:AppCompatActivity() {


    private lateinit var mGLSurfaceView: GLSurfaceView

    override fun onCreate(savedInstanceState: Bundle?) {

        requestWindowFeature(Window.FEATURE_NO_TITLE)
        super.onCreate(savedInstanceState)
        mGLSurfaceView=GLSurfaceView(this@LessonOneActivity)

        if (checkSupportsEs(0x20000)) {
            mGLSurfaceView.setEGLContextClientVersion(2)
            mGLSurfaceView.setRenderer(LessonOneRender())

        }else{
            return
        }

        setContentView(mGLSurfaceView)

    }

    override fun onResume() {
        super.onResume()
        mGLSurfaceView?.let {
            it.onResume()
        }
    }

    override fun onPause() {
        super.onPause()
        mGLSurfaceView?.let {
            it.onPause()
        }
    }

    private fun checkSupportsEs(esVersion: Int):Boolean{
        val activityManager=getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        val configurationInfo =activityManager.deviceConfigurationInfo

        Log.d("regEsVerion","reqGleSVersion:${configurationInfo.reqGlEsVersion},${configurationInfo.reqGlEsVersion>esVersion}")
        return configurationInfo.reqGlEsVersion>esVersion
    }
}
